module Shell where

import System.Console.Isocline
import Control.Concurrent.MVar
import Text.Megaparsec
import Process
import Syntax

prompt :: IO String
prompt = return "hashell"

shell :: IO ()
shell = do
  line <- prompt >>= readline
  case line of
    "exit" -> return ()
    l  -> do
      case parse pipelineP "hashell" l of
        Left e -> print e
        Right p -> do
          closeFds <- newMVar []
          CommandResult outputIO statusIO <- invoke p closeFds ""
          outputIO >>= putStrLn
          statusIO >>= print
      shell
